<?php

namespace app\api\controller;

use app\api\model\Video as VideoModel;
use think\Db;


/**
 * 门店列表
 * Class Shop
 * @package app\api\controller
 */
class Video extends Controller
{
    /**
     * 视频列表
     * @return array
     * @throws \think\exception\DbException
     */
    public function lists()
    {
        // 整理请求的参数
        $param = array_merge($this->request->param(), [
            'status' => 10
        ]);
        // 获取列表数据
        $model = new VideoModel;
        $list = $model->getList($param, $this->getUser(false));
        return $this->renderSuccess($list);
    }


    /**
     * 视频分类
     * @param
     * @return array
     * @throws \think\exception\DbException
     */
    public function category()
    {
        $category = Db::name('video_category')
            ->where('wxapp_id', $this->wxapp_id)
            ->select()->toArray();
        return $this->renderSuccess($category);
    }

    /**
     * 视频集列表
     * @param
     * @return array
     * @throws \think\exception\DbException
     */
    public function gatherList($video_id)
    {
        $list = Db::name('video_gather')
            ->where('wxapp_id', $this->wxapp_id)
            ->where('video_id', $video_id)
            ->select()->toArray();
        $user = $this->getUser();
        foreach ($list as &$value) {
            $value['auth'] = $user['grade_id'] >= $value['grade_id'] ? 1 : 0;
        }
//        $video = Db::name('video')->find($video_id);
//        if ($video['grade_id'] > 0) {
//            $list['vip'] = 1;
//        } else {
//            $list['vip'] = 0;
//        }
        return $this->renderSuccess($list);
    }

    /**
     * 获取一集地址
     * @param
     * @return array
     * @throws \think\exception\DbException
     */
    public function grtOne($gather_id)
    {
        $url = Db::name('video_gather')
            ->where('wxapp_id', $this->wxapp_id)
            ->where('gather_id', $gather_id)
            ->value('video_url');
        return $this->renderSuccess($url);
    }


}